﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using mydddd.Web.code;
using Maticsoft.DBUtility;

namespace wdgl.admin.sysAdmin
{
    public partial class List : BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitLoad();
            }
        }

        private void bind()
        {

            string columns = @" LoginName
                                            ,RealName
                                            ,Password
                                            ,(SELECT rname FROM sysrolepopedom WHERE sysrolepopedom.id=sysAdmin.sysrolepopedom_rname) as sysrolepopedom_rname
                                            ,Remark
                                            ,sort
                                            ,isdel
                                            ,ID
                                             ";


            string whereSql = " ";

            if (sysrolepopedom_rname.SelectedValue != "%")
            {
                whereSql += " and sysrolepopedom_rname=" + sysrolepopedom_rname.SelectedValue;
            }




            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            if (ttbSearchMessage.Text.Length > 0)
            {
                dictionary.Add("RealName", ttbSearchMessage.Text + "%"); //模糊查询条件
            }

            //BindFineUI  页面分页绑定方法
            FineuiHelper.Grid.BindFineUI(columns, Grid1, "sysAdmin", whereSql, dictionary, "id");

        }

        #region gird常用方法

        //初始加载
        private void InitLoad()
        {

            FineuiHelper.DropDownList.Bind(sysrolepopedom_rname, "sysrolepopedom", "rname", "id");
            sysrolepopedom_rname.Items.Insert(0, new FineUI.ListItem("全部", "%"));

            bind();
        }

       


        //添加
        protected void Button_add_OnClick(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(
                   Window1.GetShowReference("sysAdminAdd.aspx", "添加"));

        }

        //删除
        protected void Button_delete_OnClick(object sender, EventArgs e)
        {
            string ids = GetDataKeysBySelectedRow(Grid1);
            if (ids.Length == 0)
            {
                Alert.Show("请选择记录！");
                return;
            }
            mydddd.BLL.sysAdmin bll = new mydddd.BLL.sysAdmin();
            bll.DeleteList(ids);
            bind();
        }

        //每页显示数目
        protected void ddlPageSize_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            bind();
        }

        //分页事件
        protected void Grid1_OnPageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
       
            bind();
        }

        //排序事件
        protected void Grid1_OnSort(object sender, GridSortEventArgs e)
        {
            Grid1.SortDirection = e.SortDirection;
            Grid1.SortField = e.SortField;
    
            bind();
        }

        //重置搜索
        protected void ttbSearchMessage_OnTrigger1Click(object sender, EventArgs e)
        {
            ttbSearchMessage.Text = String.Empty;
            ttbSearchMessage.ShowTrigger1 = false;
            DelPageState();
            bind();
        }

        //搜索
        protected void ttbSearchMessage_OnTrigger2Click(object sender, EventArgs e)
        {
            ttbSearchMessage.ShowTrigger1 = true;
            DelPageState();
            bind();
        }


        //页面重置
        protected void Button_Repage_OnClick(object sender, EventArgs e)
        {
            DelPageState();
            PageContext.Refresh();
        }

        //删除页面状态
        private void DelPageState()
        {
            Grid1.PageIndex = 0;
            Grid1.SortDirection = "";
            Grid1.SortField = "id";
            DelCookie("page" + Request.PhysicalPath.Split('.')[0]);
        }
        #endregion

        protected void Window1_OnClose(object sender, WindowCloseEventArgs e)
        {
            bind();
        }
    }
}